package com.tubi.edu.info.manager.service;

import com.tubi.edu.info.manager.dao.TeacherDao;
import com.tubi.edu.info.manager.domain.Teacher;

//老师业务员
public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    //添加老师
    public boolean addTeacher(Teacher t) {
        return teacherDao.addTeacher(t);
    }
    //判断接受的id是否存在
    public boolean isExists(String id) {
        //  获取库管老师的数组
         Teacher[] teachers  = teacherDao.findAllTeacher();
         //拿到数据进行遍历查看
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher != null && id.equals(teacher.getId())){
                flag = true;
                break;
            }
        }
        return flag;
    }
    //查询老师信息
    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < allTeacher.length; i++) {
            if(allTeacher[i] != null) {
                flag = true;
                break;
            }
        }
        if(flag) {
            return  allTeacher;
        }else {
            return null;
        }
    }
    //删除老师
    public void deleteStudentById(String id) {
        teacherDao.deleteStudentById(id);
    }
    //修改老师
    public void updateTeacher(String id, Teacher t) {
        teacherDao.updateTeacher(id,t);
    }
}
